package com.well.register.console.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.well.register.console.aop.WellException;
import com.well.register.console.domain.ServerModel;
import com.well.register.console.model.server.QueryRegisterServerParam;
import com.well.rpc.model.RegisterModel;

import java.util.List;

/**
 * <p>
 * register server service
 * </p>
 *
 * @author weedo
 * @since 2022/8/10
 */
public interface ServerService extends IService<ServerModel> {

    /**
     * 根据查询条件查询server model
     * @param param
     * @return
     */
    List<ServerModel> registerServerModel(QueryRegisterServerParam param);

    /**
     * 根据注册模型获取servermodel
     * @param model
     * @return
     */
    ServerModel oneRegisterServer(RegisterModel model);

    /**
     * 服务上线
     * @param model
     * @return
     */
    boolean serverUp(RegisterModel model);

    /**
     * 服务下线
     * @param model
     * @return
     */
    boolean serverDown(RegisterModel model);

    /**
     * 优雅下线服务
     * @param id
     * @throws WellException
     */
    void serverDownGracefully(int id) throws WellException;

    /**
     * 恢复注册服务状态
     */
    void restoreRegisterServerState();

    /**
     * 查询当前服务中是否存在活跃的注册服务
     * @param registerModel
     * @return
     */
    int countActivityServer(RegisterModel registerModel);

    /**
     *  check 集群中是否存在有效的servername
     * @param namespace
     * @param group
     * @param servername
     * @return
     */
    boolean haveValidServer(String namespace, String group, String servername);
}
